package module4.homework;

import java.io.Serializable;

public class StudentInformation implements Serializable {

    private String name;
    private String number;
    private int age;


    public StudentInformation() {
    }

    public StudentInformation(String name, String number, int age) {
        setName(name);
        setNumber(number);
        setAge(age);
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getNumber() {
        return number;
    }

    public void setNumber(String number) {
        Integer it = Integer.valueOf(number);
        if (it > 10010 && it < 10050) {
            this.number = number;
        } else {
            try {
                throw new NumberException("学生序号不在指定范围内!!!");
            } catch (NumberException e) {
                e.printStackTrace();
            }
        }
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        if (age > 0 && age < 150) {
            this.age = age;
        } else {
            try {
                throw new AgeException("年龄不对啊!!!");
            } catch (AgeException e) {
                e.printStackTrace();
            }
        }
    }

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", number='" + number + '\'' +
                ", age=" + age +
                '}';
    }
}
